package entity;

public class Student extends Person {
    private Course[] courses;
    private int courseCount;

    public Student(String id, String name) {
        super(id, name);
        this.courses = new Course[5];
        this.courseCount = 0;
    }

    public void selectCourse(Course course) {
        if (courseCount < courses.length) {
            courses[courseCount] = course;
            courseCount++;
        }
    }

    public void dropCourse(String courseId) {
        for (int i = 0; i < courseCount; i++) {
            if (courses[i].getId().equals(courseId)) {
                // 移动后面的元素向前
                for (int j = i; j < courseCount - 1; j++) {
                    courses[j] = courses[j + 1];
                }
                courseCount--;
                break;
            }
        }
    }

    @Override
    public void printWorkSheet() {
        super.printWorkSheet();
        System.out.println("类型: 学生课表");
        for (int i = 0; i < courseCount; i++) {
            System.out.println(courses[i]);
        }
        System.out.println();
    }
}